$(document).ready(function () {
	$('li.sub').click(function (e) {
		$clickItem = $(e.target);
		if ($clickItem.attr('href') === '#') {
			e.preventDefault();
			$(this)
				.siblings()
				.find('ul.sub-menu')
				.stop()
				.slideUp('fast');
			$(this)
				.find('ul.sub-menu')
				.stop()
				.slideToggle('fast');
		}
	});

	$('div.show-block').hover(function () {
		$(this)
		.find('div.show-block-mask').stop().fadeToggle()
		.end().find('div.show-block-extra').stop().slideToggle();
	});

	function fixFullPageSize() {
		var windowHeight = $(window).height();
		$('div.full-page').height(windowHeight - 80);
	}
	fixFullPageSize();
	$(window).resize(fixFullPageSize);

	// event page
	var firstYear = $('[data-year]').first().data('year');
	var initLeft = getLeft(firstYear);

	function getLeft (year) {
		return (year - 2000) * 100 + 100;
	}
	
	var $eventImgs = $('div.event-imgs');
	var $eventPointer = $('div.event-pointer');
	var $rulerImg = $('div.ruler img');
	// initail event img position
	$eventImgs.animate({
		'left': initLeft + 'px'
	}, 1000, 'easeOutQuart', function () {
		$('[data-year]').first().addClass('active');
	});
	$eventPointer.delay(200).animate({
		'left': initLeft - 15 + 'px'
	}, 1000, 'easeOutQuart');

	$eventImgs.children().click(function () {
		var $this = $(this);
		var clickYear = $this.data('year');
		var clickLeft = $this.offset().left;
		var relativeLeft = clickLeft - $eventImgs.offset().left;
		
		$('[data-year].active').removeClass('active');
		$this.addClass('active');

		$eventImgs.stop().animate({
			'left': initLeft - relativeLeft + 'px'
		}, 1000, 'easeOutQuart');

		var rulerLeft =  (firstYear - clickYear) * 100;
		$rulerImg.stop().animate({
			'left': rulerLeft, 
		}, 1000, 'easeOutQuart');
	});
	

	// center design-total
/*	function centerDesignTotal () {
		var totalLen = $('div.design-total').width();
		var realLen = $('div.design-main').width() + 45 +
					  $('div.show-block-sm').width() +
					  $('div.design-title').width();
		$('div.design-total').css('margin-left', (totalLen - realLen + 15) / 2);
	}
	centerDesignTotal();
	$(window).resize(centerDesignTotal);*/
});